package com.college.resource.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.CampusInformation;
import com.college.common.pojo.dto.resource.AddCampusInformationDTO;
import com.college.common.pojo.dto.resource.QueryCampusInformationDTO;
import com.college.common.pojo.dto.resource.UpdateCampusInformationDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.mapper.CampusInformationMapper;
import com.college.resource.service.CampusInformationService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 校园资讯 服务实现类
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class CampusInformationServiceImpl extends ServiceImpl<CampusInformationMapper, CampusInformation> implements CampusInformationService {
    @Autowired
    private CampusInformationMapper campusInformationMapper;

    @Override
    public List<CampusInformation> queryList(QueryCampusInformationDTO queryCampusInformationDTO) {
        return campusInformationMapper.queryList(queryCampusInformationDTO);
    }

    @Override
    public List<CampusInformation> queryListPage(QueryCampusInformationDTO queryCampusInformationDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return campusInformationMapper.queryList(queryCampusInformationDTO);
    }

    @Override
    public CommonResult<String> addCampusInformation(AddCampusInformationDTO addCampusInformationDTO) {
        return this.save(addCampusInformationDTO)? CommonResult.success("校园资讯新增成功") : CommonResult.failed("校园资讯新增失败");
    }

    @Override
    public CommonResult<String> updateCampusInformation(UpdateCampusInformationDTO updateCampusInformationDTO) {
        CampusInformation campusInformation = ObjectUtil.objectCopyProperties(updateCampusInformationDTO, CampusInformation.class);
        return this.updateById(campusInformation) ? CommonResult.success("校园资讯修改成功") : CommonResult.failed("校园资讯修改失败");
    }
}
